{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HITS & ECI"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![hits.png](hits.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:17.465741Z",
     "start_time": "2019-07-04T14:30:17.456668Z"
    }
   },
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "import numpy as np\n",
    "import pickle \n",
    "import pandas as pd\n",
    "\n",
    "fr = open('MatrixD.pkl','rb')  \n",
    "dat = pickle.load(fr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:18.115860Z",
     "start_time": "2019-07-04T14:30:18.110681Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(102, 242)"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = dat[1995]\n",
    "len(df[0]), len(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MATRIX TO EDGELIST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:19.427176Z",
     "start_time": "2019-07-04T14:30:19.377452Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24684"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dat = []\n",
    "for i in range(len(df)):\n",
    "    for j in range(len(df[i])):\n",
    "        #if df[i][j]:\n",
    "        dat.append(['row'+str(i), 'col' + str(j), df[i][j]])\n",
    "\n",
    "len(dat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:21.474200Z",
     "start_time": "2019-07-04T14:30:21.399558Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Name: \\nType: DiGraph\\nNumber of nodes: 344\\nNumber of edges: 24684\\nAverage in degree:  71.7558\\nAverage out degree:  71.7558'"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "G = nx.DiGraph()\n",
    "for i in dat:\n",
    "    G.add_edge( i[1], i[0], weight = i[2])\n",
    "\n",
    "nx.info(G)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# hits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:26.863726Z",
     "start_time": "2019-07-04T14:30:25.386439Z"
    }
   },
   "outputs": [],
   "source": [
    "h, a = nx.hits(G)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:27.741296Z",
     "start_time": "2019-07-04T14:30:27.727046Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "102"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "country_ids = [i for i in list(G.nodes) if 'col' in i]\n",
    "df1 = [(i, h[i]) for i in country_ids]\n",
    "df1 = pd.DataFrame(df1, columns = ['id', 'hub'])\n",
    "df1['ids'] = [int(i.split('col')[1]) for i in df1['id'].tolist()]\n",
    "df1 = df1.sort_values(by = 'ids', ascending = True)\n",
    "len(df1['hub'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:30:28.677689Z",
     "start_time": "2019-07-04T14:30:28.664020Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "242"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_ids = [i for i in list(G.nodes) if 'row' in i]\n",
    "df2 = [(i, a[i]) for i in country_ids]\n",
    "df2 = pd.DataFrame(df2, columns = ['id', 'aut'])\n",
    "df2['ids'] = [int(i.split('row')[1]) for i in df2['id'].tolist()]\n",
    "df2 = df2.sort_values(by = 'ids', ascending = True)\n",
    "len(df2['aut'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ECI & PCI\n",
    "\n",
    "https://nbviewer.jupyter.org/github/hashc/Skills/blob/master/ecomplexity.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:15:29.149291Z",
     "start_time": "2019-07-04T14:15:28.921966Z"
    }
   },
   "outputs": [],
   "source": [
    "def RCA(Xcp):\n",
    "    \"\"\"\n",
    "    Xcp is a numpy.matrix type\n",
    "    --|steel|oil|chip|bean|clothes\n",
    "    --|--|--|--|--|--\n",
    "    USA|1|1|1|1|0\n",
    "    China|1|0|0|1|1\n",
    "    Viet Nam|0|0|0|1|1\n",
    "    \"\"\"\n",
    "    if type(Xcp) is not np.matrix:\n",
    "        if type(Xcp) is np.array or list:\n",
    "            Xcp = np.matrix(Xcp)\n",
    "        else:\n",
    "            raise ValueError('Xcp must be matrix')\n",
    "    else:\n",
    "        pass\n",
    "    B = Xcp.sum(1)*Xcp.sum(0) \n",
    "    Sum = Xcp.sum()\n",
    "    return Xcp*Sum/B\n",
    "    \n",
    "def fliterRCA(R):\n",
    "    M = R>1\n",
    "    return M.astype(float)\n",
    "\n",
    "\n",
    "def Get_eci_pci(M):\n",
    "    d = M.sum(1).T.tolist()[0]\n",
    "    u = M.sum(0).tolist()[0]\n",
    "    D = np.diag([1.0/i if i>0 else 0. for i in d])\n",
    "    U = np.diag([1.0/i if i>0 else 0. for i in u])\n",
    "    mcp1 = D * M\n",
    "    mcp2 = M * U\n",
    "    \n",
    "    Mcc = mcp1 * mcp2.T\n",
    "    Mpp = mcp2.T * mcp1\n",
    "    eigvals, eigvecs = np.linalg.eig(Mpp)\n",
    "    eigvecs = np.real(eigvecs)\n",
    "    # Get eigenvector corresponding to second largest eigenvalue\n",
    "    eig_index = eigvals.argsort()[-2]\n",
    "    kp = eigvecs[:, eig_index]\n",
    "    kc = mcp1 @ kp\n",
    "    s1 = np.sign(np.corrcoef(M.sum(1).reshape(-1), kc.reshape(-1))[0, 1])\n",
    "    eci = s1 * kc\n",
    "    pci = s1 * kp  \n",
    "    return eci.T.tolist()[0],pci.T.tolist()[0]\n",
    "\n",
    "def Get_eci_pci_sparse(M):\n",
    "    d = M.sum(1).T.tolist()[0]\n",
    "    u = M.sum(0).tolist()[0]\n",
    "    nd,nu = len(d),len(u)\n",
    "    D1 = scipy.sparse.csc_matrix(([1.0/i if i>0 else 0. for i in d], (range(nd), range(nd))),shape=(nd,nd))\n",
    "    U1 = scipy.sparse.csc_matrix(([1.0/i if i>0 else 0. for i in u], (range(nu), range(nu))),shape=(nu,nu))\n",
    "    M = sparse.csc_matrix(M)\n",
    "    mcp1 = D1 * M\n",
    "    mcp2 = M * U1\n",
    "    Mcc = mcp1 @ mcp2.T\n",
    "    Mpp = mcp2.T @ mcp1\n",
    "    A=scipy.sparse.csc_matrix(Mpp)\n",
    "    eigvals, eigvecs = scipy.sparse.linalg.eigs(A, k=2)\n",
    "    eigvecs = np.real(eigvecs)\n",
    "    # Get eigenvector corresponding to second largest eigenvalue\n",
    "    eig_index = eigvals.argsort()[-2]\n",
    "    kp = eigvecs[:, eig_index]\n",
    "    kc = mcp1 @ kp\n",
    "    s1 = np.sign(np.corrcoef(M.sum(1).reshape(-1), kc.reshape(-1))[0, 1])\n",
    "    eci = s1 * kc\n",
    "    pci = s1 * kp\n",
    "    return eci,pci\n",
    "\n",
    "def Get_z_score(x):\n",
    "    x=np.array(x)\n",
    "    std=np.std(x)\n",
    "    mean=np.mean(x)\n",
    "    return (x-mean)/std"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:16:54.648823Z",
     "start_time": "2019-07-04T14:16:54.619472Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/datalab/Applications/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:19: RuntimeWarning: invalid value encountered in true_divide\n",
      "/Users/datalab/Applications/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:22: RuntimeWarning: invalid value encountered in greater\n"
     ]
    }
   ],
   "source": [
    "c = dat[1995] # MatrixD[1995]\n",
    "R = RCA(c)\n",
    "M = fliterRCA(R)\n",
    "eci,pci = Get_eci_pci(np.matrix(M))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:25:40.707438Z",
     "start_time": "2019-07-04T14:25:40.703158Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(242, 102, 102)"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(eci), len(pci), len(hub)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:31:05.960583Z",
     "start_time": "2019-07-04T14:31:05.955896Z"
    }
   },
   "outputs": [],
   "source": [
    "pci_z = Get_z_score(pci)\n",
    "eci_z = Get_z_score(eci)\n",
    "\n",
    "hub = df1['hub'].tolist()\n",
    "aut = df2['aut'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:20:53.306082Z",
     "start_time": "2019-07-04T14:20:53.300928Z"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:29:47.918047Z",
     "start_time": "2019-07-04T14:29:47.270811Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAEACAYAAACnJV25AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAF9ZJREFUeJzt3X+MLWddx/HP9+69q2xbIN171QjdXQjEiJUIbDTGgEWIkoZQRVHjtpZIvHIbjSb+Ac0m8ofZSEI0KRDarFA03COGIApCCT8SCQjRuJcAKRYIEPbaQGDbGihcQ2n79Y/Zwz27d2bOMzPP/HrO+5VMds+cc2aeZ8/ud579Pj/G3F0AgHSc6LsAAIC4COwAkBgCOwAkhsAOAIkhsANAYgjsAJAYAjsAJIbADgCJIbADQGII7ACQmJN9nPT06dO+sbHRx6kBYLQuXLjwgLufmfe6XgL7xsaG9vb2+jg1AIyWme2HvI5UDAAkhsAOAIkhsANAYgjsAJAYAjsAdGEykTY2pBMnsq+TSWun6mVUDAAslMlEOntWunQpe7y/nz2WpK2t6KejxQ4AbdvevhzUpy5dyva3gMAOAG27eLHa/oYI7ADQtrW1avsbIrADQNt2dqSVlaP7Vlay/S0gsANA27a2pN1daX1dMsu+7u620nEqMSoGALqxtdVaID+OFjsAJIbADgCJIbADQGII7ACQGAI7ACSGwA4AiWkc2M3sOjP7NzO7z8w+b2Z/GqNgAIB6Yoxjf1TSn7v7p83sGkkXzOwj7v7fEY4NAKiocYvd3b/h7p8+/P5hSfdJekrT4wIA6omaYzezDUnPkfSfMY8LAAgXLbCb2dWS/knSn7n7d3KeP2tme2a2d3BwEOu0AIBjogR2MzulLKhP3P09ea9x911333T3zTNnzsQ4LQAgR4xRMSbpbZLuc/e/aV4kAEATMVrsvyTpFkm/YmafOdxujHBcAEANjYc7uvu/S7IIZQEARMDMUwDpm0ykjQ3pxIns62TSd4laxY02AKRtMpHOnpUuXcoe7+9nj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rKkz0p6lqSfVRa8Z7cfm3nfuyQ9cYx1kPRaSX90+N53j7QOJw7f9+OSJiOtw4sl/a6yoPLSsZX/8D0vk/QpSb83xs9g5n1/Lem5I69DJ3/Lg7uDkrt/3Mw2ju3+eUlfdvevSpKZ/aOkm9z9ryTl/ntsZmuSvu3u32mxuLli1MHM7pf0yOHDx9orbb5Yn8Oh/5X0I22Us0ykz+GFkq5S9kf7f2Z2j7s/3mrBD8X6DNz9fZLeZ2YfkPQP7ZU499wxPgOT9HpJH3T3T7db4itF/lvoxOACe4GnSPqfmcf3S/qFOe95laS3t1ai6qrW4T2S3mRmz5f08TYLVkGlOpjZyyX9mqQnS3pzu0ULVqkO7r4tSWb2SkkPdBXUS1T9DG6Q9HJlF9Z7Wi1ZuKp/C3+i7D+nJ5nZM9z9rjYLF6jq57AqaUfSc8zs9sMLQGvGEtgtZ1/pzCp3f11LZamrUh3c/ZKyi9OQVK3De5RdoIak8u+SJLn738UvSi1VP4OPSfpYW4WpqWod3ijpje0Vp5aqdXhQ0qvbK85Rg+s8LXC/pOtmHj9V0td7Kktd1GEYxl6HsZdfog6tG0tg/y9JzzSzp5nZsrLOrPf1XKaqqMMwjL0OYy+/RB3a13UPc0AP9DslfUOXh/m96nD/jZK+pKwnervvclIH6kD5qcNQ68AiYACQmLGkYgAAgQjsAJAYAjsAJIbADgCJIbADQGII7ACQGAI7ACSGwA4AiSGwA0Bi/h+BBWHaMeKVVAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(hub, pci_z, 'ro')\n",
    "plt.xscale('log');\n",
    "#plt.yscale('log');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:31:15.534518Z",
     "start_time": "2019-07-04T14:31:14.824009Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw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fb0fpbAXwTVa/z5tR25mRrLnbmZGsudtLW+bZztnAQMEIIKYxUQzGEEEJ6QmEnhJDCoLATQkhhUNgJIaQwKOyEEFIYFHZCCCkMCjshhBQGhZ0QQgqDwk4IIYXxf5pfjC5ZurbIAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(aut, eci_z, 'ro')\n",
    "plt.xscale('log');\n",
    "#plt.yscale('log');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# iteration methods of eci\n",
    "\n",
    "https://github.com/hashc/Skills/blob/master/iter_eci.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:34:26.796560Z",
     "start_time": "2019-07-04T14:34:26.787331Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([2.75, 2.75, 2.75, 2.75]), array([2.25, 2.25, 2.25, 2.25]))"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as  np\n",
    "import copy \n",
    "c=np.array([[1.,1.,1.,1.],[0.,1.,0.,0.],[0.,0.,1.,1.],[0.,0.,0.,1.]])\n",
    "def eci(c):\n",
    "\tc.astype(np.float64)\n",
    "\ta=c.sum(1)\n",
    "\tb = c.sum(0)\n",
    "\ta0 = copy.deepcopy(a)\n",
    "\tb0 = copy.deepcopy(b)\n",
    "\tfor _ in range(100):\n",
    "\t\ta1 = copy.deepcopy(a)\n",
    "\t\tfor i in range(len(a)):\n",
    "\t\t\ta1[i] = 1.0*sum([b[j] for j in range(len(a)) if c[i,j]])/a0[i]\n",
    "\t\tb1 = copy.deepcopy(b)\n",
    "\t\tfor j in range(len(b)):\n",
    "\t\t\tb1[j] =  1.0*sum([a[i] for i in range(len(b)) if c[i,j]])/b0[j]\n",
    "\t\t#print(a1,b1)\n",
    "\t\ta=a1\n",
    "\t\tb=b1\n",
    "\treturn a,b\n",
    "\n",
    "eci(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# END"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:23:52.105008Z",
     "start_time": "2019-07-04T14:23:52.093165Z"
    }
   },
   "outputs": [],
   "source": [
    "import pickle \n",
    "\n",
    "fr = open('cdata_res.pkl','rb')  \n",
    "dat = pickle.load(fr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:23:52.596741Z",
     "start_time": "2019-07-04T14:23:52.592556Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['ECI', 'density', 'cog', 'PCI'])"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dat.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-04T14:23:53.074770Z",
     "start_time": "2019-07-04T14:23:53.070748Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.11142756821655171"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dat['ECI']['~019343c06c6a15aa47']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:anaconda]",
   "language": "python",
   "name": "conda-env-anaconda-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
